package grape.crm.service.customerassociatedcontactperson.impl;

import grape.crm.service.customerassociatedcontactperson.map.CustomerAssociatedContactPersonServiceMapper;
import grape.crm.service.customerassociatedcontactperson.param.AddCustomerAssociatedContactPersonParam;
import grape.crm.service.customerassociatedcontactperson.po.CustomerAssociatedContactPerson;
import grape.crm.service.customerassociatedcontactperson.mapper.CustomerAssociatedContactPersonMapper;
import grape.crm.service.customerassociatedcontactperson.api.ICustomerAssociatedContactPersonService;
import grape.common.service.common.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 关联联系人表 服务实现类
 * </p>
 *
 * @author yangwei
 * @since 2020-09-24
 */
@Service
public class CustomerAssociatedContactPersonServiceImpl extends BaseServiceImpl<CustomerAssociatedContactPersonMapper, CustomerAssociatedContactPerson> implements ICustomerAssociatedContactPersonService {

    @Autowired
    private CustomerAssociatedContactPersonServiceMapper customerAssociatedContactPersonServiceMapper;

    @Override
    public boolean batchAddCustomerAssociatedContactPerson(String customerId, List<AddCustomerAssociatedContactPersonParam> customerAssociatedContactPersons) {

        List<CustomerAssociatedContactPerson> customerAssociatedContactPersonList = new ArrayList<>(customerAssociatedContactPersons.size());
        CustomerAssociatedContactPerson customerAssociatedContactPerson = null;
        for (AddCustomerAssociatedContactPersonParam customerAssociatedContactPersonParam : customerAssociatedContactPersons) {
            customerAssociatedContactPerson = customerAssociatedContactPersonServiceMapper.paramToPo(customerAssociatedContactPersonParam);
            customerAssociatedContactPerson.setCustomerId(customerId);
            customerAssociatedContactPersonList.add(customerAssociatedContactPerson);
        }
        // 保存关联联系人
        return saveBatch(customerAssociatedContactPersonList);
    }
}
